//
//  UIScrollView+ZBRefresh.m
//  ZBCommonUI
//
//  Created by xzb on 2019/1/6.
//

#import "UIScrollView+ZBRefresh.h"
#import <MJRefresh/MJRefresh.h>

@implementation UIScrollView (ZBRefresh)


- (void)zb_headerRefreshingBlcok:(void (^)())block
{
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        if (block) block();
    }];
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.textColor = [UIColor whiteColor];
    header.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    
    self.mj_header = header;
}

- (void)zb_blackHeaderRefreshingBlcok:(void (^)())block
{
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        if (block) block();
    }];
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.textColor = [UIColor blackColor];
    header.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    self.mj_header = header;
}

- (void)zb_endHeaderRefreshing
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.mj_header endRefreshing];
    });
}

@end
